package com.tyk.bookstore.back.member.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tyk.bookstore.back.member.model.entity.DeliveryAddressDo;
import com.tyk.bookstore.back.member.model.query.DeliveryAddressAddQuery;
import com.tyk.bookstore.back.member.model.query.DeliveryAddressPageQuery;
import com.tyk.bookstore.back.member.model.query.DeliveryAddressUpdateQuery;
import com.tyk.bookstore.back.member.model.vo.DeliveryAddressPageVo;
import com.tyk.bookstore.back.member.model.vo.DeliveryAddressVo;
import com.tyk.bookstore.back.member.repository.DeliveryAddressRepository;
import com.tyk.bookstore.back.member.service.DeliveryAddressService;
import com.tyk.bookstore.back.member.util.MapStructMember;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class DeliveryAddressServiceImp  implements DeliveryAddressService {
    private final DeliveryAddressRepository deliveryAddressRepository;
    private final MapStructMember mapStructMember;


    @Override 
    public DeliveryAddressVo getDeliveryAddressById(Long id) {
        DeliveryAddressDo deliveryAddress = deliveryAddressRepository.selectById(id);
        return mapStructMember.toDeliveryAddressVo(deliveryAddress);
    }

    @Override 
    public DeliveryAddressPageVo getDeliveryAddressPage(DeliveryAddressPageQuery query) {
        Page<DeliveryAddressDo> page = new Page<>(query.getPage(), query.getLimit());
        deliveryAddressRepository.selectPage(page, new LambdaQueryWrapper<>());
        return mapStructMember.toDeliveryAddressPageVo(page);
    }

    @Override 
    public void addDeliveryAddress(DeliveryAddressAddQuery query) {
        DeliveryAddressDo deliveryAddress = mapStructMember.toDeliveryAddressDo(query);
        deliveryAddressRepository.insert(deliveryAddress);
    }

    @Override 
    public void updateDeliveryAddressById(DeliveryAddressUpdateQuery query) {
        DeliveryAddressDo deliveryAddress = mapStructMember.toDeliveryAddressDo(query);
        deliveryAddressRepository.updateById(deliveryAddress);
    }

    @Override 
    public void deleteDeliveryAddressById(Long id) {
        deliveryAddressRepository.deleteById(id);
    }

    @Override 
    public void deleteDeliveryAddressByIds(List<Long> ids) {
        deliveryAddressRepository.deleteBatchIds(ids);
    }
}
